package com.atguigu.gmall.user.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.user.model.UserAddress;
import com.atguigu.gmall.user.service.UserAddressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: atguigu
 * @create: 2023-09-15 09:39
 */
@RestController
@RequestMapping("/api/user")
public class UserApiController {

    @Autowired
    private UserAddressService userAddressService;


    /**
     * 根据用户ID查询用户收件地址列表
     *
     * @param userId
     * @return
     */
    @ApiOperation("根据用户ID查询用户收件地址列表")
    @GetMapping("/inner/findUserAddressListByUserId/{userId}")
    public List<UserAddress> findUserAddressListByUserId(@PathVariable("userId") Long userId) {
        return userAddressService.findUserAddressListByUserId(userId);
    }


    /**
     * 提供给移动端 查询我的收件地址列表
     * @param request
     * @return
     */
    @GetMapping("userAddress/auth/findUserAddressList")
    public Result findUserAddressList(HttpServletRequest request){
        String userId = AuthContextHolder.getUserId(request);
        return Result.ok(userAddressService.findUserAddressListByUserId(Long.valueOf(userId)));
    }
}
